// src/stores/modules/member.ts

import type { AddressItem } from '@/types/address'
import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useAddressStore = defineStore(
    'address',
    () => {
        const selectAddress = ref<AddressItem>()

        const changeSelectAddress = (val: AddressItem) => {
            selectAddress.value = val
        }

        const deleteSelectAddress = (val: AddressItem) => {
            if (selectAddress.value == val) {
                selectAddress.value = undefined
            }
        }

        // 记得 return
        return { changeSelectAddress, selectAddress, deleteSelectAddress }
    },
    {
        // 小程序端配置
        persist: {
            storage: {
                getItem(key) {
                    return uni.getStorageSync(key)
                },
                setItem(key, value) {
                    uni.setStorageSync(key, value)
                },
            },
        },
    },
)